/********************************************************************
	created:	2008/09/11
	created:	11:9:2008   19:23
	filename: 	h:\SimoneEngine\qianye\src\common\qyCommon.h
	author:		Xiong Jiayu
	copyright:  
	purpose:	
*********************************************************************/

#pragma once

#ifndef __QYCOMMON_H__
#define __QYCOMMON_H__

//-----------------------------------------------------------------------
/**
	inline 
*/
#if defined ( WIN32 )
#	define QY_INLINE	__forceinline
#else
#	define QY_INLINE	inline
#endif

//-----------------------------------------------------------------------
/**
	memory leak
*/
//#if defined ( WIN32 )
//#	if	defined( _DEBUG ) | defined( DEBUG )
//#		include <iostream>
//#		include <crtdbg.h>
////#		define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
////#		define new DEBUG_NEW
//#	endif // _DEBUG
//#endif // _WIN32



//-----------------------------------------------------------------------
/**
	common header
*/
typedef unsigned char		uint8_t;			
typedef signed char			int8_t;
typedef unsigned short		uint16_t;		
typedef signed short		int16_t;
typedef unsigned int		uint32_t;			
typedef signed int			int32_t;
typedef unsigned long long	uint64_t;	
typedef long long			int64_t;

#ifdef IPHONE
typedef unsigned long		uintptr_t;			
#endif

#ifndef _WIN32
typedef unsigned short  WORD;
typedef unsigned int DWORD;
struct RECT
{
    long left;
    long top;
    long right;
    long bottom;
};
#endif

#include <assert.h>

#ifdef _WIN32
#   include <iostream>
#else
#   include <stdio.h>
#   include <stdlib.h>
#endif

#define qy_SafeDelete( p )			if ( p )	{ delete p; p = 0; }
#define qy_SafeDeleteArray( p )		if ( p )	{ delete[] p; p = 0; }
#define qy_SafeFree( p )			if ( p )	{ free(p); p = 0; }
#define qy_SafeRelease( p )			if ( p )	{ p->Release(); p = 0; }

#ifdef _WIN32
#   define QY_OFFSET_OF(CLASS,MEMBER) (reinterpret_cast<unsigned long>(&(reinterpret_cast<CLASS*>(16)->MEMBER))-16)
#else
#include <stddef.h>
#   define QY_OFFSET_OF(CLASS,MEMBER) ((reinterpret_cast<int>(&reinterpret_cast<CLASS*>(16)->MEMBER)-16))
#endif

#if defined (__INTEL_COMPILER) 
#define QY_ALIGN(size) __declspec(align((size)))
#elif defined (__GNUC__)
#define QY_ALIGN(size) 	__attribute__ ((aligned (size)))
#elif defined (_MSC_VER)
#define QY_ALIGN(size) __declspec(align(size))
#else
#define QY_ALIGN(size)
#endif

#define QY_IS_ALIGNED(addr,size)  ((((unsigned int)(addr))%(size))==0)

#endif
